@include('admin.layout.css')
@include('admin.layout.js')




<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">

    <div class="layui-form-item">
        <label class="layui-form-label">商家图片</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="test1">上传图片</button>
            <input type="hidden" name="img_url" id="img_url" value="{{$info['img_url']}}">
            <div class="layui-upload-list" >
                <img class="layui-upload-img" src="{{$info['img_url']}}"  id="img_url_show" width="92px" height="92px">
                <p id="demoText"></p>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">商家名称</label>
        <div class="layui-input-block">
            <input type="text"  name="shop_name" value="{{$info['shop_name']}}"  placeholder="请输入商家名称" autocomplete="off" class="layui-input" >
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">请选择城市</label>
        <div class="layui-input-inline">
            <select name="province_id" lay-filter = "province">
                <option value="">请选择省会</option>
                @foreach($province as $value)
                    <option value="{{$value['id']}}" @if($value['id'] == $info['province_id']) selected @endif>{{$value['name']}}</option>
                @endforeach
            </select>
        </div>

        <div class="layui-input-inline">
            <select name="city_id" id="city" lay-filter = "city">
                <option value="">请选择城市</option>
                @foreach($city as $value)
                    <option value="{{$value['id']}}" @if($value['id'] == $info['city_id']) selected @endif>{{$value['name']}}</option>
                @endforeach
            </select>
        </div>


        <div class="layui-input-inline">
            <select name="area_id" id="area" lay-filter = "area">
                <option value="">请选择区域</option>
                @foreach($area as $value)
                    <option value="{{$value['id']}}" @if($value['id'] == $info['area_id']) selected @endif>{{$value['name']}}</option>
                @endforeach
            </select>
        </div>





    </div>





        <div class="layui-form-item">
            <a href="https://lbs.amap.com/tools/picker" target="_blank"><label class="layui-form-label">地址名称(点击跳转)</label></a>
            <div class="layui-input-inline">
                <input type="text"  name="shop_address" value="{{$info['shop_address']}}"  placeholder="请输入地址名称" autocomplete="off" class="layui-input" >
            </div>

            <label class="layui-form-label">地址经纬度</label>
            <div class="layui-input-inline">
                <input type="text"  name="address_po" value="{{$info['address_po']}}"   placeholder="请输入地址经纬度" autocomplete="off" class="layui-input" >
            </div>
        </div>

    <input type="hidden" name="user_id" value="{{$user_id}}">

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="submit" id="submit" value="确认">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="取消">
    </div>

</div>


<script>

    UI.upload('#test1',function (res) {
        if (res.code !== 200) {
            Utils.errorToast(res.msg);
        }else{
            Utils.successToast('上传成功');
            $('#img_url_show').attr('src',res['data']['src']);
            $('#img_url').val(res['data']['src']);
        }
    },'video');

    layui.use(['laydate','form'], function() {

        let form = layui.form;

        form.on('select(province)', function(data){
            let value = data.value;
            $("#city").empty();
            HttpUtils.get('{{route('admin.get_area')}}?parentid='+value,{},function (res){
                $("#city").append("<option value=''>请选择城市</option>")
                for(let i=0;i<res['data'].length;i++){
                    $("#city").append("<option value='"+res['data'][i]['id']+"'>"+res['data'][i]['name']+"</option>")
                }
                form.render();
            });
        });

        form.on('select(city)', function(data){
            let value = data.value;
            $("#area").empty();
            HttpUtils.get('{{route('admin.get_area')}}?parentid='+value,{},function (res){
                $("#area").append("<option value=''>请选择区域</option>")
                for(let i=0;i<res['data'].length;i++){

                    $("#area").append("<option value='"+res['data'][i]['id']+"'>"+res['data'][i]['name']+"</option>")
                }
                form.render();
            });
        });


        form.on('submit(submit)', function(data){

            Api.add("{{route('admin.users.set_shop_user')}}",data.field,function(res){
                if (res.code !== 200){
                    Utils.errorToast(res.msg);
                    return;
                }
            });
        });


    });
</script>
